<?php 
/*****************************************************************
Created : 02/02/2011
Author : Mr. Nawin.I
*****************************************************************/
define('ADODB_ASSOC_CASE', 2); 
$rel_path="./";
include_once($rel_path."adodb/adodb.inc.php");
include_once($rel_path."adodb/tohtml.inc.php");
include_once($rel_path."adodb/adodb-pager.inc.php");

$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;

class DB {
		var $Connect;
		var $ResultSet;
		var $AffectedRows;
		var $NumRows;
		var $db;

	// constructor connect handle
	function DB(){


		 $Host = "localhost";
	       $Username = "root";
		 $Password = "sa";
		 $DbName = "hd";
        
         /* $Username = "copyhidef";
        $Password = "google";
        $DbName = "copyhidef";*/
		
		$DBType = "mysql";

		$this->db = NewADOConnection($DBType);
		$this->db->Connect($Host, $Username, $Password, $DbName);
		//Fix thailanguage
		$this->db->Execute("SET NAMES utf8");
		
		$this->db->Execute("SET character_set_results=utf8");
		$this->db->Execute("SET character_set_client=utf8");
		$this->db->Execute("SET character_set_connection=utf8");
	}

	function getDB() {
		return $this->db;
	}
	
	function ExecuteData($sqlScript){
		return $this->db->Execute($sqlScript);
	}
	function ExecuteDataAndGetID($sqlScript){
		$this->db->Execute($sqlScript);
		return $this->db->Insert_ID();
	}	
	function getLastID(){
		return $this->db->Insert_ID();
	}
	
	function InsertSqlScript($sqlScript,$val){
		$rs=$this->ExecuteData($sqlScript . " and 1=0 ");
		return $this->db->GetInsertSQL($rs,$val);
	}
	
	function UpdateSqlScript($sqlScript,$val){
		$rs=$this->ExecuteData($sqlScript);
		return $this->db->GetUpdateSQL($rs,$val);
	}
	
	function GetPager($sql,$list_page) {
		$pager = new ADODB_Pager($this->db,$sql);
		return $pager;
	}
}
?>